package cn.buk.tms.dao;

import cn.buk.common.sc.CommonSearchCriteria;
import cn.buk.tms.dto.PassengerRecency;
import cn.buk.tms.entity.config.EntAlipayConfig;
import cn.buk.tms.entity.config.EntEotmsConfig;
import cn.buk.tms.entity.config.EtermEntConfig;
import cn.buk.tms.sc.SearchCustomerCriteria;
import cn.buk.tms.entity.misc.*;

import java.util.Date;
import java.util.List;

/**
 * @author yfdai
 */
public interface EnterpriseDao {

  /**
   * 查找企业参数
   * @return 未找到，则返回空字符串；否则，返回找到的值
   */
  String getEnterpriseConfig(int enterpriseId, String itemCode);

  int getEnterpriseConfig(int enterpriseId, String itemCode, int defaultValue);

  /**
   * 设置指定的企业参数
   */
  int setEnterpriseConfig(int enterpriseId, String itemCode, String itemValue);


  int create(Enterprise enterprise);

  Enterprise getEnterpriseById(int id);


  /**
   * 获取付费用户的付费截止期限
   */
  Date getEntExpireDate(int enterpriseId);


  /**
   * 获取默认BSP出票机的序号, 默认返回1
   */
  int getBspPrinterNo(int enterpriseId);


  List<Enterprise> searchEnterprise(CommonSearchCriteria sc);

  int getMonitoredDomPolicyCount(int enterpriseId);

  int getMonitoredIntlPolicyCount(int enterpriseId);

  String getAirlineInCrazyMode(int enterpriseId);

  EnterpriseBalance getEnterpriseBalance(int authorizer, int enterpriseId);

  EnterpriseBalance getEnterpriseBalance(int enterpriseId);

  /**
   * 查找被授权企业的余额表
   * @param enterpriseId 授权企业id
   * @return 余额表
   */
  List<EnterpriseBalance> searchMyEntBalance(int enterpriseId);


  int updateEntCashBalance(int enterpriseId, int opMode, int modifyAmount, String remark);

  int updateMyEntCashBalance(int enterpriseId, int objectEnterpriseId, int opMode, int modifyAmount,
                             String remark);

  int buyPoints(int enterpriseId);

  int createEntCreditLimit(int enterpriseId, int authorizee, int creditLimit);

  List<CustomerDepartment> searchCustomerDepartments(int enterpriseId, SearchCustomerCriteria sc);

  /**
   * 查找客户的职位级别
   */
  List<CustomerPosition> searchCustomerPositions(int enterpriseId, SearchCustomerCriteria sc);

  List<CustomerPosition> searchCustomerPositions(int enterpriseId, int customerId);

  int saveCustomerDepartment(int enterpriseId, String username, CustomerDepartment department);

  /**
   * 创建供应商
   */
  int createSupplier(int enterpriseId, Supplier supplier);

  /**
   * 根据id获取供应商
   */
  Supplier getSupplierById(int supplierId);

  Supplier getSupplierById(int enterpriseId, int id);

  /**
   * 获取默认的供应商
   */
  Supplier getSupplierByDefault(int enterpriseId);

  /**
   * 修改供应商资料
   */
  int updateSupplier(int enterpriseId, Supplier supplier);

  /**
   * 按照条件查找供应商
   */
  List<Supplier> searchSuppliers(int enterpriseId, CommonSearchCriteria sc);

  /**
   * 获取所有供应商
   */
  List<Supplier> getAllSuppliers(int enterpriseId);


  /**
   * 查找支出支付方式
   */
  List<PaymentMethod> searchPaymentMethods(int enterpriseId, CommonSearchCriteria sc);

  List<IncomeMethod> searchIncomeMethods(int enterpriseId, CommonSearchCriteria sc);

  /**
   * 新建支出支付方式
   */
  int createPaymentMethod(int enterpriseId, PaymentMethod info);

  /**
   * 修改支出支付方式
   */
  int updatePaymentMethod(int enterpriseId, PaymentMethod info);

  int createIncomeMethod(int enterpriseId, IncomeMethod o);

  int updateIncomeMethod(int enterpriseId, IncomeMethod o);

  /**
   * 根据id查找支付方式
   */
  PaymentMethod getPaymentMethodById(int id);

  /**
   * 根据id和企业id查找支付方式
   */
  PaymentMethod getPaymentMethodById(int enterpriseId, int id);

  /**
   * 获取默认的支出支付方式
   */
  PaymentMethod getPaymentMethodByDefault(int enterpriseId);

  IncomeMethod getIncomeMethodById(int id);

  List<CustomerDepartment> searchDepartmentsByCustomer(int enterpriseId, int customerId);

  List<Groups> searchGroups(int enterpriseId, CommonSearchCriteria sc);

  int createGroup(Groups o);

  Groups getGroupInfoById(int id);

  int updateGroupRole(int enterpriseId, int groupId, String[] roles);

  int addUserToGroup(int groupId, int userId);

  int deleteUserFromGroup(int groupId, int userId);

  List<RoleInfo> searchRoles(int enterpriseId);

  List<RolePrivilege> searchRolePrivileges(int enterpriseId, CommonSearchCriteria sc);

  int deleteRolePrivilege(int enterpriseId, int id);

  int addRolePrivilege(int enterpriseId, String role, Integer[] privilegeIds);

  List<SysPrivilege> searchPrivileges(int enterpriseId);


  List<CustomerNote> searchCustomerNotes(int enterpriseId, CommonSearchCriteria sc,
                                         final int customerId, final int noteType);

  int createCustomerNote(int enterpriseId, int customerId, int noteType, String name);

  /**
   * 查找企业客户的订单备注
   */
  List<CustomerNote> searchCustomerNotesByType(int enterpriseId, int customerId, int noteType);

  int deleteCustomerNoteById(int enterpriseId, int id);


  List<FakeTicketNo> searchFakedTickets(int enterpriseId, CommonSearchCriteria sc);

  int createFakedTicket(FakeTicketNo f);

  List<EntDepartment> searchEntDepartments(int enterpriseId, CommonSearchCriteria sc);

  List<EntDepartment> searchEntDepartmentByWwDeptId(int enterpriseId, int wwDeptId);

  int saveEntDepartment(EntDepartment dept);

  EntDepartment getEntDepartment(int id);

  int deleteEntDepartment(int enterpriseId, int id);

  List<FuelSurcharge> searchFuelSurcharges(int enterpriseId, CommonSearchCriteria sc);

  int createFuelSurcharge(int enterpriseId, int mileageType, Date effectDate, int surcharge);

  int deleteFuelSurcharge(int enterpriseId, int id);

  Passenger getPassengerById(int enterpriseId, int id);

  int deletePassengerInfo(int userId, int id);


  /**
   * 查找旅行代码
   */
  List<PnrTourCode> searchTourCodes(final int enterpriseId);

  int createPnrTourCode(PnrTourCode pnrTourCode);

  int updatePnrTourCode(PnrTourCode pnrTourCode);

  /**
   * 保存eterm参数设置
   */
  int saveEtermConfig(int enterpriseId, String host, int port, String username, String password);

  EtermEntConfig searchEtermConfig(int enterpriseId);

  AuthCodeInfo getAuthCodeInfo(String authCode);

  int createAuthCodeInfo(String authCode, String mobile, int enterpriseId, String orderType,
                         int orderId, String shortUrl);

  /**
   * 设置默认供应商
   */
  int setDefaultSupplier(int enterpriseId, int supplierId);

  /**
   * 设置BSP供应商
   */
  int setBspSupplier(int enterpriseId, int supplierId, int bspType);

  List<DataFieldInfo> searchDataFields();

  int createDataTemplate(DataFieldExportTemplate template);

  DataFieldInfo getDataFieldInfoById(int id);

  List<DataFieldExportTemplate> searchDataTemplates(int enterpriseId, CommonSearchCriteria sc);

  List<DataFieldExportTemplate> searchDataTemplates(int enterpriseId);

  DataFieldExportTemplate searchDataTemplate(int enterpriseId, int templateNo);

  int deleteDataTemplateById(int enterpriseId, int id);

  /**
   * 刷新企业客户最近一次购买的时间
   */
  void refreshCustomerRecency();

  /**
   * 刷新乘机人最近12个月的购买次数和最近一次购买时间
   */
  void refreshPassengerRecency(PassengerRecency pr);

  /**
   * 刷新供应商最近三个月的使用频率
   */
  void refreshSupplierFrequency();

  /**
   * 是否启用了隐藏客户名
   */
  boolean getHideCustomerName(int enterpriseId);

  /**
   * 是否启用“客户只看自己的订单”
   */
  boolean isOnlySeeOwn(int enterpriseId);

  /**
   * 查找在EnterpriseConfig(t107)中配置了参数的企业客户的企业id
   *
   * @param ownerId 所有者id
   * @param mode    0-享受其它优惠的客户，1-享受机票大客户优惠的客户
   */
  List<Integer> searchCustomerEnterpriseId(int ownerId, int mode);

  List<CustomerFlightDiscount> searchCustomerFlightDiscounts(int enterpriseId, int customerEnterpriseId);

  int saveCustomerFlightDiscount(CustomerFlightDiscount info);

  int deleteCustomerFlightDiscount(int enterpriseId, int customerEnterpriseId, String policyCode);

  /**
   * 创建车型组
   */
  int createVehicleGroupInfo(int enterpriseId, String username, VehicleGroupInfo info);

  /**
   * 查找车型组
   *
   * @param enterpriseId 当前用户的企业id
   * @param sc           查找条件
   * @return 车型组信息数组
   */
  List<VehicleGroupInfo> searchVehicleGroups(int enterpriseId, CommonSearchCriteria sc);

  /**
   * 查找车型组映射
   */
  List<VehicleGroupMapping> searchVehicleGroupMappings(int enterpriseId, List<Integer> ids);

  /**
   * 获取车型组
   *
   * @param id 车型组Id
   * @return 车型组对象
   */
  VehicleGroupInfo getVehicleGroupInfoById(int id);

  /**
   * 保存车型组映射
   *
   * @param info         映射对象
   * @return 操作结果
   */
  int createVehicleGroupMapping(int enterpriseId, String username, VehicleGroupMapping info);

  /**
   * 根据ID查找企业部门信息
   */
  CustomerDepartment getCustomerDepartmentById(int id);

  /**
   * 根据企业部门ID查找企业部门信息
   *
   * @param enterpriseId 企业ID
   * @param customerId   客户ID
   * @param deptId       部门ID
   * @return 如果有，返回企业部门信息
   */
  CustomerDepartment getCustomerDepartmentByDeptId(int enterpriseId, int customerId, int deptId);

  CustomerDepartment getCustomerDepartmentByDeptName(int enterpriseId, int customerId, String deptName);

  int saveCustomerPosition(int enterpriseId, String username, CustomerPosition dto);

  int deleteCustomerPosition(int enterpriseId, String username, int id);

  CustomerPosition getCustomerPositionByName(int enterpriseId, int customerId, String positionName);

  int saveApiProductSupplier(int enterpriseId, int productType, int supplierId);

  List<ProductDefaultSupplier> searchApiProductSupplier(int enterpriseId);

  int deleteApiProductSupplier(int enterpriseId, int id);

  int savePassengers(List<Passenger> passengers);

  ProductDefaultSupplier searchSupplierByApiProduct(int enterpriseId, int productType);

  /**
   * 创建或修改 客户服务分组
   */
  int createOrUpdateCustomerServiceGroup(int enterpriseId, String username, int id, String code, String name);

  List<GroupCustomerService> searchCustomerServiceGroups(int enterpriseId);

  int updateCustomerGroup(int enterpriseId, String username, int customerId, int groupId);

  GroupCustomerService searchGroupCustomerService(int enterpriseId, String groupCode);

  int deleteCustomerGroup(int enterpriseId, String username, int customerId);

  int updateRepresentativeGroup(int enterpriseId, String username, int userId, int groupId);

  int deleteRepresentativeGroup(int enterpriseId, String username, int userId);

  /**
   * 根据分组代码，查找该分组代码包含的企业客户的id
   *
   * @param enterpriseId             企业id
   * @param customerServiceGroupCode 分组代码
   * @return 返回符合条件的企业客户id
   */
  List<Integer> searchCustomerIdsByGroupCode(int enterpriseId, String customerServiceGroupCode);

  List<CustomerServiceTemplate> searchCustomerServiceTemplates(int enterpriseId);

  int createOrUpdateCustomerServiceTemplate(int enterpriseId, String username, CustomerServiceTemplate tpl);

  int updateCustomerTemplate(int enterpriseId, String username, int customerId, int templateId, String templateCode);

  /**
   * 改进模板代码查找客户服务费模板
   */
  CustomerServiceTemplate searchCustomerServiceTemplate(int enterpriseId, String templateCode);

  /**
   * 查找客户适用的服务费模板
   */
  CustomerServiceTemplate searchServiceTemplateByCustomer(int enterpriseId, int customerId);

  /**
   * 根据id获取服务费模板
   */
  CustomerServiceTemplate getCustomerServiceTemplateById(int enterpriseId, int id);

  List<CustomerServiceFlightRule> searchCustomerServiceFlightRules(int enterpriseId, String templateCode);

  int createOrUpdateCustomerServiceFlightRule(int enterpriseId, String username, String templateCode, CustomerServiceFlightRule fltRule);


  int saveBlobMapping(int enterpriseId, String username, String fileName, String blobName, String contentType, long fileSize);

  AzureStorageFileNameMapping getBlobMappingById(int id);

  /**
   * 停用供应商
   *
   * @param enterpriseId 企业id
   * @param id           供应商id
   * @param username     用户名
   * @param remark       停用说明
   */
  int disableSupplier(int enterpriseId, int id, String username, String remark);

  /**
   * 根据供应商出票类型查找供应商
   */
  List<Supplier> searchSupplierByTicketingType(int enterpriseId, int ticketingType);

  List<TmsTask> searchTasks(int enterpriseId, CommonSearchCriteria sc);

  List<TmsTask> searchTasks(int enterpriseId, int taskType, Date taskDate);

  int finishDailyTask(int enterpriseId, String username, int taskId);

  void updateDailyTaskSendFileTime(int enterpriseId, String username, int taskId);

  List<ReportTemplateInfo> searchReportTemplates(int enterpriseId);

  int updateCustomerReportTemplate(int enterpriseId, String username, int customerId, int templateId);


  /**
   * 查找乘机人适用的机票政策
   */
  List<PassengerFlightPolicy> searchPassengerFlightPolicies(int enterpriseId, int psgId);

  List<TmsWwAppChat> searchWwAppChats(int enterpriseId);

  int createWwAppChat(TmsWwAppChat appChat);

  void updateWwAppChat(TmsWwAppChat appChat);

  List<TmsWwUser> searchWwUsers(int enterpriseId);

  TmsWwAppChat searchWwAppChat(int enterpriseId, String chatId);

  TmsWwAppChat searchWwAppChatByType(int enterpriseId, String chatType);

  int updateAlipayConfig(int enterpriseId, String username, String mainAccount, String appId, String privateKey, String alipayPublicKey, String returnUrl, String notifyUrl);

  List<EntAlipayConfig> searchAlipayConfigs(int enterpriseId);

  int deleteAlipayConfig(int enterpriseId, String username, int id);

  List<EntEotmsConfig> searchEntEotmsConfig(int enterpriseId);
}
